package cn.linpq.menu;

import cn.linpq.frame.MineFrame;
import cn.linpq.util.Tools;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Desc : 游戏菜单类
 * ClassName : cn.linpq.menu.GameMenu
 *
 * @author : 林鹏群
 * @date : 2022/12/12 11:28
 */
public class GameMenu extends JMenu {
    private MineFrame mineFrame;

    public GameMenu(MineFrame mineFrame) {
        this.setText("游戏");
        this.mineFrame = mineFrame;
        //初始化开局菜单
        JMenuItem start = new JMenuItem("开始");
        //初始化初级菜单
        JMenuItem elementary = new JMenuItem("初级");
        //初始化中级菜单
        JMenuItem intermediate = new JMenuItem("中级");
        //初始化高级菜单
        JMenuItem advanced = new JMenuItem("高级");
        JMenuItem harder = new JMenuItem("闯关");
        //初始化退出菜单
        JMenuItem exit = new JMenuItem("退出");
        //添加开局、初级、中级、高级、退出菜单
        this.add(start);
        this.add(elementary);
        this.add(intermediate);
        this.add(advanced);
        this.add(harder);
        this.add(exit);
        //绑定开局、初级、中级、高级、退出菜单ActionListener事件
        start.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mineFrame.restart();
            }
        });
        elementary.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Tools.elementary();
                mineFrame.restart();
            }
        });
        intermediate.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Tools.intermediate();
                mineFrame.restart();
            }
        });
        advanced.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Tools.advanced();
                mineFrame.restart();
            }
        });
        harder.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Tools.harder();
                mineFrame.restart();
            }
        });
        exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
    }
}
